package cn.seqdata.cxf.provider;

import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.apache.cxf.jaxrs.utils.JAXRSUtils;

import cn.seqdata.cxf.wrapper.WrapperBean;
import cn.seqdata.cxf.wrapper.WrapperViolations;

@Provider
public class ConstraintViolationExceptionMapper implements ExceptionMapper<ConstraintViolationException> {

	@Override
	public Response toResponse(ConstraintViolationException exception) {
		WrapperBean wrapper = new WrapperViolations(exception.getConstraintViolations());

		return JAXRSUtils.toResponseBuilder(Response.Status.OK)
			.entity(wrapper)
			.build();
	}
}
